home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / jrh-rkrm-partone / intuition / images_text / simpleimage.e < prev   
Text File  |  1995-03-26  |  2KB  |  63 lines

  1. -> simpleimage.e - Program to show the use of a simple Intuition Image.
  2.  
  3. OPT OSVERSION=37  -> E-Note: silently require V37
  4.  
  5. MODULE 'exec/memory',
  6.        'intuition/intuition'
  7.  
  8. ENUM ERR_NONE, ERR_WIN
  9.  
  10. RAISE ERR_WIN IF OpenWindowTagList()=NIL
  11.  
  12. CONST MYIMAGE_LEFT=0, MYIMAGE_TOP=0,
  13.       MYIMAGE_WIDTH=24, MYIMAGE_HEIGHT=10,
  14.       MYIMAGE_DEPTH=1
  15.  
  16. -> E-Note: get some Chip memory and copy list (quick, since LONG aligned)
  17. PROC copyListToChip(data)
  18.   DEF size, mem
  19.   size:=ListLen(data)*SIZEOF LONG
  20.   mem:=NewM(size, MEMF_CHIP)
  21.   CopyMemQuick(data, mem, size)
  22. ENDPROC mem
  23.  
  24. -> Main routine. Open required window and draw the images.  This routine opens
  25. -> a very simple window with no IDCMP.  See the chapters on "Windows" and
  26. -> "Input and Output Methods" for more info.  Free all resources when done.
  27. PROC main() HANDLE
  28.   DEF win=NIL:PTR TO window, myImage:image
  29.   win:=OpenWindowTagList(NIL, [WA_WIDTH,   200,
  30.                                WA_HEIGHT,  100,
  31.                                WA_RMBTRAP, TRUE,
  32.                                NIL])
  33.  
  34.   -> This contains the image data.  It is a one bit-plane open rectangle which
  35.   -> is 24 pixels wide and 10 high.  Make sure it's in CHIP memory by allocating
  36.   -> a block of chip memory with a call like this: NewM(data_size,MEMF_CHIP),
  37.   -> and then copy the data to that block.
  38.   myImage:=[MYIMAGE_LEFT, MYIMAGE_TOP, MYIMAGE_WIDTH,
  39.             MYIMAGE_HEIGHT, MYIMAGE_DEPTH,
  40.             copyListToChip([$FFFFFF00, $C0000300, $C0000300, $C0000300,
  41.                             $C0000300, $C0000300, $C0000300, $C0000300,
  42.                             $C0000300, $FFFFFF00]),
  43.             1, 0, NIL]:image  -> Use first bit-plane, clear unused planes
  44.  
  45.   -> Draw the 1 bit-plane image into the first bit-plane (colour 1)
  46.   DrawImage(win.rport, myImage, 10, 10)
  47.  
  48.   -> Draw the same image at a new location
  49.   DrawImage(win.rport, myImage, 100, 10)
  50.  
  51.   -> Wait a bit, then quit.
  52.   -> In a real application, this would be an event loop, like the one described
  53.   -> in the Intuition Input and Output Methods chapter.
  54.   Delay(200)
  55.  
  56. EXCEPT DO
  57.   IF win THEN CloseWindow(win)
  58.   SELECT exception
  59.   CASE ERR_WIN; WriteF('Error: Failed to open window.\n')
  60.   CASE "MEM";   WriteF('Error: Ran out of (chip) memory.\n')
  61.   ENDSELECT
  62. ENDPROC
  63.